package com.caigou.modules.famous.adpter

import android.view.View
import android.widget.Button
import com.caigou.modules.famous.R
import com.caigou.modules.famous.bean.MyChallengeItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @author #Suyghur.
 * Created on 2021/12/08
 */
class MyChallengeItemAdapter(dataset: MutableList<MyChallengeItemBean>) :
    BaseQuickAdapter<MyChallengeItemBean, BaseViewHolder>(R.layout.item_my_challenge_list, dataset) {

    init {
        addChildClickViewIds(R.id.item_my_challenge_btn_cancel)
        addChildClickViewIds(R.id.item_my_challenge_btn_publish)
    }

    override fun convert(holder: BaseViewHolder, item: MyChallengeItemBean) {
        holder.setText(R.id.item_my_challenge_tv_type, "类型：${item.dareTypeName}")
        holder.setText(R.id.item_my_challenge_tv_period, "起始期数：${item.period}期")
        holder.setText(R.id.item_my_challenge_tv_target, "目标：${item.successDesc}")
        holder.setText(R.id.item_my_challenge_tv_now, "当前：${item.successResultDesc}")
        if (item.moneyRule == 0) {
            holder.setText(R.id.item_my_challenge_iv_money, "免费")
        } else {
            holder.setText(R.id.item_my_challenge_iv_money, "${item.moneyRule}元")
        }
        val btnCancel = holder.getView<Button>(R.id.item_my_challenge_btn_cancel)
        val btnOngoing = holder.getView<Button>(R.id.item_my_challenge_btn_ongoing)
        val btnPublish = holder.getView<Button>(R.id.item_my_challenge_btn_publish)
        when (item.status) {
            0 -> {
                btnCancel.visibility = View.VISIBLE
                btnCancel.text = "放弃"
                btnCancel.isClickable = true

                btnOngoing.visibility = View.VISIBLE
                btnOngoing.text = "进行中"

                btnPublish.visibility = View.VISIBLE
                btnPublish.text = "发表"
                btnPublish.isClickable = true
            }
            1 -> {
                btnCancel.visibility = View.GONE

                btnOngoing.visibility = View.VISIBLE
                btnOngoing.text = "已完成"

                btnPublish.visibility = View.VISIBLE
                btnPublish.text = "挑战"
            }
            2 -> {
                btnCancel.visibility = View.VISIBLE
                btnCancel.text = "已放弃放弃"
                btnCancel.isClickable = false

                btnOngoing.visibility = View.GONE

                btnPublish.visibility = View.VISIBLE
                btnPublish.text = "挑战"
                btnPublish.isClickable = true
            }
        }
    }
}